package cn.iocoder.yudao.module.pay.framework.impl.free;

import cn.iocoder.yudao.module.api.pay.order.dto.UnifiedOrderCreateDTO;
import cn.iocoder.yudao.module.api.pay.order.eums.UnifiedPayChannelEnum;
import cn.iocoder.yudao.module.api.pay.order.vo.UnifiedOrderVO;
import cn.iocoder.yudao.module.api.pay.refund.dto.UnifiedRefundCreateDTO;
import cn.iocoder.yudao.module.api.pay.refund.vo.UnifiedRefundVO;
import cn.iocoder.yudao.module.api.pay.transfer.dto.UnifiedTransferCreateDTO;
import cn.iocoder.yudao.module.api.pay.transfer.vo.UnifiedTransferVO;
import cn.iocoder.yudao.module.pay.framework.impl.AbstractPayClient;
import cn.iocoder.yudao.module.pay.framework.impl.NonePayClientConfig;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * 免支付的 PayClient 实现类，类似于模拟支付，其结果都是成功的
 *
 * @author 山野羡民
 */
public class FreePayClient extends AbstractPayClient<NonePayClientConfig> {

    private static final String RESPONSE_SUCCESS_DATA = "FREE_SUCCESS";

    public FreePayClient(NonePayClientConfig config) {
        super(UnifiedPayChannelEnum.FREE.getCode(), config);
    }

    @Override
    protected void doInit() {
        
    }

    @Override
    protected UnifiedOrderVO doUnifiedOrder(UnifiedOrderCreateDTO dto) {
        return UnifiedOrderVO.successOf("FREE-" + dto.getPayNo(), "", LocalDateTime.now(),
                dto.getPayNo(), RESPONSE_SUCCESS_DATA);
    }

    @Override
    protected UnifiedOrderVO doGetOrder(String payNo) {
        return UnifiedOrderVO.successOf("FREE-" + payNo, "", LocalDateTime.now(), payNo, RESPONSE_SUCCESS_DATA);
    }

    @Override
    protected UnifiedOrderVO doParseOrderNotify(Map<String, String> params, String body, Map<String, String> headers) {
        throw new UnsupportedOperationException("免支付无支付回调");
    }

    @Override
    protected boolean doCloseOrder(String payNo) throws Throwable {
        return true;
    }

    @Override
    protected UnifiedRefundVO doUnifiedRefund(UnifiedRefundCreateDTO dto) {
        return UnifiedRefundVO.successOf("FREE-" + dto.getRefundNo(), LocalDateTime.now(), dto.getRefundNo(), RESPONSE_SUCCESS_DATA);
    }

    @Override
    protected UnifiedRefundVO doGetRefund(String payNo, String refundNo) {
        return UnifiedRefundVO.successOf("FREE-" + refundNo, LocalDateTime.now(),
                refundNo, RESPONSE_SUCCESS_DATA);
    }

    @Override
    protected UnifiedRefundVO doParseRefundNotify(Map<String, String> params, String body, Map<String, String> headers) {
        throw new UnsupportedOperationException("免支付无退款回调");
    }

    @Override
    protected UnifiedTransferVO doUnifiedTransfer(UnifiedTransferCreateDTO dto) {
        return UnifiedTransferVO.successOf("FREE-" + dto.getTransferNo(), LocalDateTime.now(),
                dto.getTransferNo(), RESPONSE_SUCCESS_DATA);
    }

    @Override
    protected UnifiedTransferVO doGetTransfer(String transferNo) {
        return UnifiedTransferVO.successOf("FREE-" + transferNo, LocalDateTime.now(),
                transferNo, RESPONSE_SUCCESS_DATA);
    }

    @Override
    protected UnifiedTransferVO doParseTransferNotify(Map<String, String> params, String body, Map<String, String> headers) {
        throw new UnsupportedOperationException("免支付无转账回调");
    }

}
